package cn.pegasus.teamwork.pegasus.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.iyizhan.teamwork.base.util.PageObject;
import cn.iyizhan.teamwork.base.util.ParameterEunm;
import cn.iyizhan.teamwork.base.util.ReMessage;
import cn.pegasus.teamwork.manager.controller.BaseManagerController;
import cn.pegasus.teamwork.pegasus.entity.BussUcenterArea;
import cn.pegasus.teamwork.pegasus.entity.BussUserInfo;
import cn.pegasus.teamwork.pegasus.mapper.BussUserInfoMapper;
import cn.pegasus.teamwork.pegasus.service.BussUserInfoService;

/**
 * 用户信息
 * @author 40854
 *
 */
@Controller
@RequestMapping("/userInfo")
public class UserInfoControlller extends BaseManagerController<BussUserInfo, BussUserInfoMapper>{
	private static final Logger logger = LoggerFactory.getLogger(UserInfoControlller.class);
	
	@Autowired
	private BussUserInfoService userInfoService;
	
	/**
	 * 查询用户列表
	 */
	@RequestMapping(value = "/list",method = {RequestMethod.GET})
	 public ModelAndView list(@RequestParam Map<String, Object> map){
		 ModelAndView view = new ModelAndView("user/user-list");
		 if(map.isEmpty()){
			map.put("pageData", 10);
			map.put("curPage", 1);
		}
		 try{
			 PageObject<BussUserInfo> dicList = userInfoService.PageList(map);
			 view.addObject("list", dicList);
			 view.addObject("map", map);
		 }catch(Exception e){
			 logger.error("查询用户列表信息异常",e.getMessage());
		 }
		 return view;
	 }
	
	/**
	 * 屏蔽/解除
	 * id  用户ID
	 * userStatus   状态  1禁用  2 解禁
	 */
	@ResponseBody
	@RequestMapping(value="/update")
	public Map<String,Object> update(@RequestParam Map<String, Object> map){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			userInfoService.updateUser(getAdmin().getId(), map);
            resultMap = ReMessage.resultBack(ParameterEunm.SUCCESSFUL_CODE, null);
        } catch (Exception e) {
            logger.error("操作用户状态异常", e);
            resultMap = ReMessage.resultBack(ParameterEunm.ERROR_500_CODE, null);
        }
		return resultMap;
	}
	/**
	 * 查询用户详情
	 */
	@RequestMapping(value="/findUserInfo")
	 public ModelAndView findUserInfo(@RequestParam(value="id",required = false) Integer id){
		 ModelAndView view = new ModelAndView("user/user-info");
		 BussUserInfo area = userInfoService.findUserInfo(id);
		 view.addObject("userInfo", area);
		 return view;
	 }
}
